﻿#region Using
/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-11-15
Description:CQuery_ReportList.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text;
using FineUI;
using FTchina.SearchQuery;
using FTchina.Library;
using FTchina;
using PWMIS.DataMap.Entity;
#endregion
public partial class CQuery_ReportList_cs : BasePage 
{

    
    string ReturnPage = "CQuery_ReportList.aspx";
 
    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化搜索模型
    string WindowsPage = "CQuery_ReportListaction.aspx";//弹出窗口的页面地址

    protected void Page_Load(object sender, EventArgs e)
    {
        
 		if (!IsPostBack)
        {	
			btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
            btnNew.OnClientClick = Window1.GetShowReference(WindowsPage, "新增"); 
            if (qm.WorkPage != ReturnPage)
            {
                
                qm.WorkPage = ReturnPage;
                qm.Key1 = string.Empty;
            }
            BindGrid(qm);
		}
    }
	
	 
    #region 绑定列表
    private void BindGrid(QueryModel qm)
    {
        BindGrid(qm,false);
    }

    /// <summary>
    /// 绑定表格
    /// </summary>
    private void BindGrid(QueryModel qm, bool IsToExcel)
    {
        //每页条数
        Grid1.PageSize = 15;
        
        FTchina.Models.CQuery_ReportList mCQuery_ReportList = new FTchina.Models.CQuery_ReportList();
		
		//拼接查询条件
        OQLCompare cmp = new OQLCompare(mCQuery_ReportList);
        OQLCompare cmpResult = (cmp.Comparer(mCQuery_ReportList.Id, OQLCompare.CompareType.Like, "%" + qm.Key1 + "%"));

        OQL q = new OQL(mCQuery_ReportList);
        q.Select().Where(cmpResult).OrderBy(mCQuery_ReportList.Id, "desc");//按条件查询条件
		
        int count = EntityQuery<FTchina.Models.CQuery_ReportList>.QueryList(q, mCQuery_ReportList).Count;//获取分页前的条数
		
		if (IsToExcel)
        {//如果是导出Excel
            FTchina.OfficeHelper.ToExcel.IListToExcel(EntityQuery<FTchina.Models.CQuery_ReportList>.QueryList(q, mCQuery_ReportList));
            return;
        }
		
        q.Limit(Grid1.PageSize, Grid1.PageIndex + 1);//分页       
        List<FTchina.Models.CQuery_ReportList> list = EntityQuery<FTchina.Models.CQuery_ReportList>.QueryList(q, mCQuery_ReportList);//分页后绑定数据源

        Grid1.RecordCount = count;
        Grid1.DataSource = list;
        Grid1.DataBind();
        
        
        

        if (qm.Key1.Length > 0)
        {
            ttbSearch.Text = qm.Key1;
            ttbSearch.ShowTrigger1 = true;
        }

    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {

        Grid1.PageIndex = e.NewPageIndex;
        BindGrid(qm);
    }
    /// <summary>
    /// 删除按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        foreach (int row in Grid1.SelectedRowIndexArray)
        {
            sb.Append(Grid1.DataKeys[row][0].ToString());
            sb.Append(",");
        }
        foreach (string ids in sb.ToString().TrimEnd(',').Split(','))
        {
            
			FTchina.BLL.CQuery_ReportListManager.DeleteCQuery_ReportListById(Convert.ToInt32(ids));
        }
        BindGrid(qm);
        Grid1.SelectedRowIndexArray=new int[]{};//去除默认的选项
    }

     
    /// <summary>
    /// 弹出窗口返回的处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Window1_Close(object sender, EventArgs e)
    {
        BindGrid(qm);
    }
    #endregion

    #region 搜索过滤
    /// <summary>
    /// 点击搜索上的关闭按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ttbSearch_Trigger1Click(object sender, EventArgs e)
    {
        ttbSearch.ShowTrigger1 = false;
        ttbSearch.Text = String.Empty;//清空搜索字符串
        qm.Key1 = String.Empty;//清空搜索条件
        BindGrid(qm);
    }
    /// <summary>
    /// 点击搜索按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
    {
        ttbSearch.ShowTrigger1 = true;//显示关闭搜索按钮
        if (ttbSearch.Text.Trim().Length > 0)
        {
            qm.Key1 = ttbSearch.Text.Trim();
        }
        else
        {
            qm.Key1 = "";
        }
        BindGrid(qm);
    }
   

    #endregion


    #region 导出Excel
    /// <summary>
    /// 带过滤条件的导出，不分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcel_click(object sender, EventArgs e)
    {
        BindGrid(qm, true);        
    }
    #endregion

    
}




 

